<!--    系统配置 - 角色添加   jh -->
<template>
    <div>
        <div class="right">
           <div class="ca-box ca-p-20">
               <el-form ref="form" :model="form" label-width="120px">
                   <el-row >
                       <el-col :span="11">
                           <el-form-item label="角色名称：">
                               <el-input v-model="form.roleName" :maxlength="100" placeholder="请输入角色名"></el-input>
                           </el-form-item>
                       </el-col>
                   </el-row>
                   <el-row >
                       <el-col :span="11">
                           <el-form-item label="模块选择：" >
                               <el-select v-model="currentMenu"  placeholder="选择新增模块" class="full-width"
                                          @change="addToArr(currentMenu,menuListChecked,menuListAll,true,callBack)" >
                                   <el-option
                                       v-for="item in menuListAll"
                                       :label="item.name"
                                       :key="item.id"
                                       :value="item.id">
                                   </el-option>
                               </el-select>
                           </el-form-item>
                       </el-col>
                   </el-row>
                   <el-row class="tagStyle">
                       <el-col>
                           <el-tag
                               class="tagStyle-tag"
                               @close="closeTag(index, tag.id)"
                               v-for="(tag,index) in menuListChecked"
                               :key="tag.id"
                               closable
                               @click.native="selectModule(tag,index)"
                               :type="tag.color">
                               {{tag.name}}
                           </el-tag>
                       </el-col>
                   </el-row>
                   <!--标题区-->
                   <el-form-item>
                       <el-row class="ca-client-topic ">
                           <el-col :span="11"><span></span></el-col>
                           <el-col class="topic-font" :span="2">模块权限</el-col>
                           <el-col :span="11"><span></span></el-col>
                       </el-row>
                   </el-form-item>
                   <div>
                       <div v-for="(tab, i) in menuListChecked" :key="i" v-show="activeTag == i && editShow">
                           <!--<el-row class="ca-m-t-20 ca-m-b-20">-->
                               <!--<el-col :span="24" >-->
                                   <!--<el-checkbox  v-model="checkAll" :indeterminate="indeterminate" @change="handleCheckAll()">全选/非全选（对此模块所有权限的操作控制）</el-checkbox>-->
                               <!--</el-col>-->
                           <!--</el-row>-->
                           <div v-for="(item,index) in secondMenu" :key="index">
                               <el-form-item :label="item.name" class="ca-m-b-5">
                                   <el-checkbox
                                       :indeterminate="item.indeterminate"
                                       v-model="item.checked"
                                       @change="handleCheckedPage(item)"> 全部</el-checkbox>
                               </el-form-item>
                               <el-form-item>
                                   <el-row  class="ca-p-20 ca-m-t-10 gray" v-if="item.show">
                                       <el-col>
                                           <el-row>
                                               <el-col :span="12" v-for="(sub,index) in item.childMenus" :key="index" >
                                                   <el-checkbox :indeterminate="sub.indeterminate" v-model="sub.checked" @change="handleCheckAllChange(sub,item)"> {{sub.name}}</el-checkbox>
                                                   <el-checkbox-group v-model="sub.checkedArr" @change="handleCheckedCitiesChange(sub,item)" class="ca-m-l-20">
                                                       <el-checkbox v-for="(auth,index) in sub.childMenus" :label="auth.name" :key="index">{{auth.name}}</el-checkbox>
                                                   </el-checkbox-group>
                                              </el-col >
                                          </el-row>
                                       </el-col>
                                   </el-row>
                               </el-form-item>
                           </div>
                       </div>
                   </div>
                   <el-row >
                       <el-col class="buttonStyle">
                           <el-button type="primary" @click="addRole">确定</el-button>
                           <el-button @click="cancel">取消</el-button>
                       </el-col>
                   </el-row>
               </el-form>
           </div>
        </div>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '__views/system-settings/role/api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { arrayUnique } from '__service/utils';
    import mined from '../mixin';
    export default {
        mixins: [mined],
        data() {
            return {
                editShow: false,//编辑时显示数据
                form: {
                    'id': '',
                    'idList': [],
                    'remark': '',
                    'roleName': ''
                },
                checkAll: false,
                indeterminate: false,
                menuListAll: [], //全部的模块------------模块选择
                menuListChecked: [],//选中的下拉项列表----模块选择
                currentMenu: '',//当前选中的项值---------模块选择
                menuId: '',//选中的menu id -------------模块选择
                secondMenu: [], //选中的menu 的所有权限
                roleId: this.$route.params.roleId,
                roleInfo: this.$route.params.roleInfo,
                curentTagIndex: 0,//当前的tag下标
                previousTagIndex: 0,//上一个tag下标
                activeTag: 0,
                allId: [],//选中的id
                allParentId: [],//选中的id的父级
                modelData: [],//模块的数据
            }
        },
        watch: {
//            currentMenu: function () {
//                this.getSelectItem()
//                this.renderPage()
//            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                vm.getPullList();
                if (vm.$route.params.roleId === '-1') {
                    vm.getAuthMenu();
                } else {
                    vm.getRoleDetail();
                    vm.form.id = vm.$route.params.roleId;
                }
            });
        },
        mounted() {
        },
        methods: {
            cancel() {
                this.$router.push({ name: 'system-settings-role-manage'})
            },
            renderPage() {
                this.allId.map((id)=>{
                    this.secondMenu.map((item)=> {
                        if (item.childMenus.length !== 0) {
                            item.childMenus.map((sub)=> {
                                if (sub.childMenus.length !== 0 ) {
                                    sub.childMenus.map( (auth)=> {
                                        if (auth.id === id ) {
                                            sub.checkedArr.push(auth.name)
                                        }
                                    })
                                }
                            })
                        }
                    })
                })
            },
            // 删除模块
            closeTag(index, id) {
                this.$confirm('是否删除此模块的权限?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.menuListChecked.splice(index, 1);
                    this.modelData.splice(index, 1);
                    //删除的时候改变当前模块的值
                    if (this.menuListChecked.length !== 0) {
                        this.currentMenu = this.menuListChecked[0].id
                    } else {
                        this.currentMenu = ''
                    }
                    let params = {
                        roleId: this.roleId,
                        menuId: id,
                    };
                    apiHttp(api.GET_AUTH_LIST, params).then(ret => {
                        if (ret.resCode === STATUS_HTTP_SUCCESS) {
                            let list = ret.data
                            let ids = [];
                            let newId = [];
                            list.map((item) => {
                                ids.push(item.id);
                                ids.push(item.parentId);//删除模块的id
                                if (item.childMenus.length !== 0) {
                                    item.childMenus.map((sub) => {
                                        ids.push(sub.id);
                                        if (sub.childMenus.length !== 0) {
                                            sub.childMenus.map((auth) => {
                                                ids.push(auth.id);
                                            })
                                        }
                                    })
                                }
                            })
                            this.allId.map((every, ind) => {
                                let listArr = ids.filter(x => x === every);
                                if (listArr && listArr.length > 0) {
                                    this.allId.splice(ind, 1)
                                } else {
                                    newId.push(every)
                                }
                            })
                            this.allId = [].concat(newId);
                            if (this.menuListChecked.length !== 0) {
                                this.selectModule(this.menuListChecked[0], 0)
                            }
                        }
                    });
                },() => {
//                    this.$message({
//                        type: 'info',
//                        message: '已取消删除',
//                        center: true
//                    });
                })
            },
            async callBack(id,index,isAdd,isEditFirst) { //isAdd代表添加模块//isEditFirst编辑是的显示数据
                this.menuId = id
                if (isAdd) {//添加模块
                    await this.getAuthMenu(1)
                } else if (!isAdd && isEditFirst) {//编辑时的选择显示第一个模块数据
                    await this.getAuthMenu(0,0,0,isEditFirst)
                } else {//选择模块  !isAdd
                    await this.getAuthMenu()
                }
                this.previousTagIndex = this.curentTagIndex
                this.curentTagIndex = index
                this.getSelectItem()
                this.renderPage()
                if (this.$route.params.roleId === '-1') {//新建的时候让下面的数据显示，编辑时，只有在所有模块数据加载完之后显示
                    this.editShow = true
                }
            },
            // 获取角色详情
            async getRoleDetail() {
                let params = {
                    id: this.$route.params.roleId,
                };
                let resData = await apiHttp(api.GET_ROLE_DETAIL, params);
                if (resData.resCode === STATUS_HTTP_SUCCESS) {
                    //console.log(resData,'获取角色详情获取角色详情获取角色详情')
                    this.form.roleName = resData.data.roleName || '';
                    resData.data.menuList.map(item => {
                        this.menuListChecked.push({//设置已选模块
                            id: item.id,
                            name: item.name
                        })
                    })
                    let length = this.menuListChecked.length
                    this.menuListChecked.map((every,index)=>{
                        this.menuId = every.id
                        this.getAuthMenu(1,index,length)
                    })
                    await this.addCheckedAllToAuthMenu( resData.data.menuList )
                   // await this.getAllIds(resData.data.menuList || []);
//                    this.currentMenu = this.menuListChecked[0].id
//                    await this.selectModule(this.menuListChecked[0], 0)
                }
            },
            setEditCurrentData() {//编辑时，显示第一个模块的数据
                this.currentMenu = this.menuListChecked[0].id
                this.selectModule(this.menuListChecked[0],0,true) //true 代表编辑的第一个menu显示的数据
            },
            // //给一二级添加checkedAll字段
            addCheckedAllToAuthMenu(data) {
                //添加字段
               // let roleArr = []
                data.map((item)=>{//item为每个模块
                   if (item.childMenus && item.childMenus.length !== 0) {
                       item.childMenus.map((list)=>{//list为一级
                           list.checkedArr = [];//已选中的子集id
                           list.checkedAll = false;//页面显示 父级 是否全选
                           list.isIndeterminate = false;
                           if (list.childMenus && list.childMenus.length !== 0) {
                               list.childMenus.map(( sub )=>{//sub为二级
                                   sub.checkedArr = [];//已选中的子集id
                                   sub.checkedAll = false;//页面显示 父级 是否全选
                                   sub.isIndeterminate = false;
                               })
                           }
                       })
                   }
                })
                //给添加的字段赋值
                this.dataFormat(data)
            },
            dataFormat(data) {
                data.map((item)=>{ //item为每个模块
                    if (item.childMenus && item.childMenus.length !== 0) {
                        item.childMenus.map((list)=>{ //list为一级
                            if (list.childMenus && list.childMenus.length !== 0) {
                                list.childMenus.map((sub) => { //sub为二级
                                    if (sub.childMenus && sub.childMenus.length !== 0) {
                                        sub.childMenus.map((eve) => { //eve为三级级
                                            if (eve.checked) { //先子集判断
                                                eve.checkedAll = true
                                                sub.checkedArr.push(eve.name)
                                                sub.checkedAll = sub.checkedArr.length === sub.childMenus.length ? true : false
                                            }
                                        })
                                    } else {
                                        if (sub.checked) {
                                            sub.checkedAll = true//后父级判断
                                        }
                                    }
                                    if (sub.checkedAll) {
                                        list.checkedArr.push(sub.name)
                                        list.checkedAll = list.checkedArr.length === list.childMenus.length ? true : false
                                    }
                                })
                            } else {
                                if (list.checked) {
                                    list.checkedAll = true //后父级判断
                                }
                            }
                        })
                    }
                })
                this.getCheckedId(data)
            },
            //获取返回的选中的id
            getCheckedId(data) {
                data.map((item)=> {
                    if (item.childMenus && item.childMenus.length !== 0) {
                        item.childMenus.map((list)=>{ //list为一级
                            if (list.checkedAll) { //先子集判断
                                this.allId.push(list.id)
                            }
                            if (list.childMenus && list.childMenus.length !== 0) {
                                list.childMenus.map((sub) => { //sub为二级
                                    if (sub.checkedAll) { //先子集判断
                                        this.allId.push(sub.id)
                                    }
                                    if (sub.childMenus && sub.childMenus.length !== 0) {
                                        sub.childMenus.map((eve) => { //eve为三级级
                                            if (eve.checkedAll) { //先子集判断
                                                this.allId.push(eve.id)
                                            }
                                        })
                                    }
                                })
                            }
                        })
                    }
                })
            },
            //获取其他级的菜单
            getAuthMenu(flag,arrIndex,arrLength,isEditFirst) {//arrIndex代表回显时的已选列表的下标,arrLength代表回显时的已选列表的长度
                let params = {
                    roleId: this.roleId,
                    menuId: this.menuId,
                }
                apiHttp(api.GET_AUTH_LIST,params).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.secondMenu = ret.data
                        this.secondMenu.map((item)=> {
                            item.checkedArr = []
                            item.chackedAll = false
                            item.indeterminate = false
                            item.checked = false
                            item.type = 0
                            if (item.childMenus && item.childMenus.length !== 0) {
                                item.childMenus.map((sub)=> {
                                    sub.checkedArr = []
                                    sub.chackedAll = false
                                    sub.indeterminate = false
                                    sub.checked = false
                                    item.show = true
                                    sub.type = 1
                                    if (sub.childMenus && sub.childMenus.length !== 0 ) {
                                        sub.childMenus.map( (auth)=> {
                                            auth.checkedArr = []
                                            auth.chackedAll = false
                                            auth.indeterminate = false
                                            auth.checked = false;
                                            auth.type = 2;
                                        })
                                    }
                                })
                            } else {
                                item.show = false
                            }
                        })
                        //this.setCheckbox();
                        if (isEditFirst && arguments.length === 4) {
                            this.setCheckbox(true);//true代表编辑时所有模块数据获取完成，选择第一个模块数据显示，可以显示下面的数据了
                        } else {
                            this.setCheckbox();
                        }
                        if (flag === 1) {//如果是添加模块时
                            this.modelData.push([this.secondMenu]) //存放该模块的数据
                        }
                        if (arguments.length === 3) {
                            if (arrIndex === arrLength - 1) {//如果已选的menu循环完成，在获取当前显示的数据
                                this.setEditCurrentData()
                            }
                        }
                    }
                });
            },
            // 回显
            setCheckbox(flag) {
                this.secondMenu.map((item)=> {
                    let list = this.allId.filter( x => x === item.id);
                    if (list && list.length !== 0) {
                        item.checked = true
                    }
                    if (item.childMenus && item.childMenus.length !== 0) {
                        item.childMenus.map((sub)=> {
                            let listArr = this.allId.filter( x => x === sub.id);
                            if (listArr && listArr.length !== 0) {
                                sub.checked = true
                            }
                            if (sub.childMenus && sub.childMenus.length !== 0 ) {
                                sub.childMenus.map( (auth)=> {
                                    let listArr2 = this.allId.filter( x => x === auth.id);
                                    if (listArr2 && listArr2.length !== 0) {
                                        sub.checkedArr.push(auth.name);
                                        this.handleCheckedCitiesChange(sub, item, true);
                                    }
                                    return auth;
                                })
                            } else {
                                this.handleCheckAllChange(sub, item, true);
                            }
                            return sub;
                        })
                    }
                    return item;
                });
                this.secondMenu = [].concat(this.secondMenu);
                this.parentChecked(this.secondMenu, true);
                if (flag) {
                    this.editShow = true
                }
            },
            //选择模块
            async selectModule(tag,index,isEditFirst) {
                this.activeTag = index;
                //初始化全选值
//                this.checkAll = false
                this.indeterminate = false
                //渲染页面
                await this.renderPage()
                //改变颜色
                for (let key in this.menuListChecked) {
                    if (key === index.toString()) {
                        this.menuListChecked[key].color = 'danger';
                    } else {
                        this.menuListChecked[key].color = '';
                    }
                }
                //刷新dom
                this.menuListChecked = this.menuListChecked.filter(function (item) {
                    return item
                })
                if (!isEditFirst) {
                    await this.callBack(tag.id,index)//单纯的选择模块
                } else {
                    await this.callBack(tag.id,index,false,isEditFirst)//编辑时选择显示第一个模块
                }
            },
            //获取第一级的菜单
            getPullList() {
                apiHttp(api.GET_PULL_LIST).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.menuListAll = ret.data
                        this.menuListAll.map((item)=>{
                            item.show = false
                        })
                    }
                });
            },
            //添加角色
            async addRole() {
                //数据处理
                await this.dealSeclectItem()
                let param = Object.assign({},this.form)
                if (param.roleName.trim().length === 0) {
                    this.$message({
                        message: '角色名称不能为空!',
                        type: 'warning',
                        center: true
                    });
                    return;
                }
                if (param.idList.length === 0) {
                    this.$message({
                        message: '请选择权限!',
                        type: 'warning',
                        center: true
                    });
                    return;
                }
                let ROLE = param.id.length === 0 ? api.ADD_ROLE : api.EDIT_ROLE;
                let txt = param.id.length === 0 ? '角色添加成功!' : '角色修改成功!';
                apiHttp(ROLE, param).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: txt,
                            type: 'success',
                            center: true
                        });
                        this.cancel()
                        this.$store.dispatch('refreshFieldList'); //更新字典
                    }
                });
            },
//            //选中所有
//            handleCheckAll() {
//                //console.log(this.checkAll)
//                if (this.checkAll) {
//                    this.indeterminate = false
//                    this.secondMenu.map(item => {
//                        item.checked = true
//                        item.indeterminate = false
//                        this.handleCheckedPage(item)
//                    })
//                } else {
//                    this.indeterminate = false
//                    this.secondMenu.map(item => {
//                        item.checked = false
//                        item.indeterminate = false
//                        this.handleCheckedPage(item)
//                    })
//                }
//            },
            //父级选中子集全选
            handleCheckedPage(item) {
                if (item.checked) {
                    item.indeterminate = false
                    if (item.childMenus && item.childMenus.length !== 0 ) {
                        item.childMenus.map(list => {
                            list.checked = true
                            this.handleCheckAllChange(list)
                        })
                    }
                } else {
                    item.indeterminate = false
                    if (item.childMenus && item.childMenus.length !== 0) {
                        item.childMenus.map(list => {
                            list.checked = false
                            this.handleCheckAllChange(list)
                        })
                    }
                }
                this.parentChecked(this.secondMenu)
            },
            /*
            *item 必填
            *parent 选填
            */
            handleCheckAllChange(item,parent,flag) {  //小父级  // 获取此模块权限下的所有值 name
                let arrOptions = [];
                for (let sub of item.childMenus) {
                    arrOptions.push( sub.name );
                }
                item.checkedArr = item.checked ? arrOptions : [];
                item.indeterminate = false;
                //由子到父的选择
                if (parent) {
                    this.parentChecked(parent, flag)
                }
            },
            /*
            *item 必填
            *parent 选填
            */
            handleCheckedCitiesChange(item,parent,flag) { //子集 // 这段代码是为了改变全选按钮的状态
                let checkedCount = item.checkedArr.length;
                item.checked = checkedCount === item.childMenus.length;
                item.indeterminate = checkedCount > 0 && checkedCount < item.childMenus.length;
                this.secondMenu = this.secondMenu.filter(function (eve) {
                    return eve
                })
                //由子到父的选择
                if (parent) {
                    this.parentChecked(parent,flag)
                }
            },
            //子到父的选择（子集全选，父级选中）
            parentChecked(parent,flag) {
                if (parent.childMenus) {
                    //子到父级
                    let arr = [] //记录选中的项
                    let arr2 = [] //记录不定状态的项
                    if (parent.childMenus && parent.childMenus.length > 0) {
                        parent.childMenus.map((list)=> {
                            if (list.checked) {
                                arr.push(list)
                            }
                            if (list.indeterminate) {
                                arr2.push(list)
                            }
                        })
                    }
                    if (arr.length === parent.childMenus.length) { //子集全选
                        parent.checked = true
                        parent.indeterminate = false
                        this.indeterminate = true
                    } else if (arr.length > 0 ) { // 孙级选中，爷级也不定向 // 子集 部分选中
                        parent.checked = false
                        parent.indeterminate = true
                        this.indeterminate = true
                    } else if (arr.length === 0 && arr2.length > 0 ) { // 子集不选中，并且不确定向没有的情况下//子集不选，存在不定选
                        parent.checked = false
                        parent.indeterminate = true
                        this.indeterminate = true
                    } else if (arr.length === 0 && arr2.length === 0 ) { // 子集不选中，并且不确定向没有的情况下
                        parent.checked = false
                        parent.indeterminate = false
                        this.indeterminate = false
                    } else if ( arr.length === 0 ) { //子项不选的话，父项的不确定项不显示
                        parent.checked = false
                        parent.indeterminate = true
                        this.indeterminate = true
                    } else {
                        parent.checked = false
                        parent.indeterminate = false
                        this.indeterminate = false
                    }
                } else {//大数组
                    //子到父级
                    let arr = [] //记录选中的项
                    let arr2 = [] //记录不定状态的项
                    if (parent && parent.length > 0 ) {
                        parent.map((list)=> {
                            if (list.checked) {
                                arr.push(list)
                            }
                            if (list.indeterminate) {
                                arr2.push(list)
                            }
                        })
                    }
                    if (arr.length === parent.length) { //子集全选
                        this.checkAll = true
                        this.indeterminate = false
                    } else if (arr.length > 0 ) { // 孙级选中，爷级也不定向 // 子集 部分选中
                        this.checkAll = false
                        this.indeterminate = true
                    } else if (arr.length === 0 && arr2.length > 0 ) { // 子集不选中，并且不确定向没有的情况下//子集不选，存在不定选
                        this.checkAll = false
                        this.indeterminate = true
                    } else if (arr.length === 0 && arr2.length === 0 ) { // 子集不选中，并且不确定向没有的情况下
                        this.checkAll = false
                        this.indeterminate = false
                    } else { // 子集不选中，并且不确定向没有的情况下
                        this.checkAll = false
                        this.indeterminate = false
                    }
                }
                if (!flag) {
                    this.getSelectItem()
                }
            },
            //传输的id数组处理
            async dealSeclectItem() {
                await this.getSelectItem()//筛选着所有的选择的id,不选择时删除，选择时加入数组
                if (this.allId.length !== 0) {
                    this.allId.map((son)=>{
                        this.getParentId(son) //获取所选id的父级id
                    })
                }
                let menuIds = [];
                this.menuListChecked.map(item => {
                    menuIds.push(item.id);
                });
                let idArr = [].concat(this.allParentId, menuIds);//选中的权限id与模块id结合（如果是编辑时，选中的id(即this.allId)中已有部分后台返回模块id，因此需要再次去重）
                idArr = arrayUnique(idArr);//去重
//                //数据模块剔除
 //               let firstStringArr = [] //第一个字符串组成的数组
//                idArr.map((item) =>{
//                    firstStringArr.push(item.substring(0,1))
//                })
                ////////////////////////
//                let firstStringArr = [] //第一个字符串组成的数组
//                let idArr = this.allParentId
//                this.allId.map((item) =>{
//                    firstStringArr.push(item.substring(0,1))
//                })
//                firstStringArr = arrayUnique(firstStringArr)//第一个字符串的数组 去重
//                let keyArr = []//用来存放第一个字符串及该字符串的计数
//                firstStringArr.map(son=>{
//                    keyArr.push({
//                        key: son,
//                        total: 0
//                    })
//                })
//                //筛选出第一个字符串相同的id数组，并计数
//                keyArr.map((some)=> {
//                    idArr.map(eve=> {
//                        if (some.key === eve.substring(0,1)) {
//                            some.total ++
//                        }
//                    })
//                })
//                //筛选出总个数为1的第一个字母的数组
//                let totalOneArr = []
//                keyArr.map((sub)=>{
//                    if (sub.total === 1) {
//                        totalOneArr.push(sub.key)
//                    }
//                })
//                if (totalOneArr.length > 0) {
//                    totalOneArr.map((y)=>{
//                        let index = idArr.findIndex( x => x.substring(0,1) === y);
//                        idArr.splice(index,1)
//                    })
//                }
//                this.form.idList = idArr
                this.form.idList = idArr
            },
            //筛选着所有的选择的id,不选择时删除，选择时加入数组
            getSelectItem() {
                this.secondMenu.map((item)=>{
                    if (item.checked) {
                        this.allId.push(item.id);
                    } else {
                        let index = this.allId.findIndex( x => x === item.id);
                        if (index !== -1) {
                            this.allId.splice(index, 1);
                        }
                    }
                    if (item.childMenus && item.childMenus.length > 0 ) {
                         item.childMenus.map((some)=>{
                            if (some.checked) {
                                this.allId.push(some.id);
                            } else {
                                let index = this.allId.findIndex( x => x === some.id);
                                if (index !== -1) {
                                    this.allId.splice(index, 1);
                                }
                            }
                            if (some.childMenus && some.childMenus.length > 0) {
                                 some.childMenus.map((every)=> {
                                    if (some.checkedArr) {
                                        let list = some.checkedArr.filter(x => x === every.name);
                                        if (list.length > 0) {
                                            this.allId.push(every.id);
                                        } else {
                                            let index = this.allId.findIndex( x => x === every.id);
                                            if (index !== -1) {
                                                this.allId.splice(index, 1);
                                            }
                                        }
                                    }
                                })
                            }
                        })
                    }
                })
                this.allId = arrayUnique(this.allId);
            },
            // 获取所有选中的id，并去重
            getAllIds(list) {
                let allIds = [];
                list.map((item)=>{
                    if (item.checked) {
                        allIds.push(item.id);
                    }
                    if (item.childMenus && item.childMenus.length > 0 ) {
                        item.childMenus.map((some)=>{
                            if (some.checked) {
                                allIds.push(some.id);
                            }
                            if (some.childMenus && some.childMenus.length > 0) {
                                some.childMenus.map((every)=>{
                                    if (every.checked) {
                                        allIds.push(every.id);
                                    }
                                    if (every.childMenus && every.childMenus.length > 0 ) {
                                        every.childMenus.map((x)=> {
                                            if (x.checked) {
                                                allIds.push(x.id);
                                            }
                                        })
                                    }
                                })
                            }
                        })
                    }
                })
                this.allParentId = arrayUnique(allIds);//后台返回的选中的id
            },
            //获取所有父级id
            getParentId(id) {
                let arr = []
                this.modelData.map((data)=>{
                    data.map((everyData)=>{
                        everyData.map((item)=>{
                            if (item.id === id ) {//如果父级选中，把子集放入
                                arr.push(id)
                                arr.push(item.parentId)
                                if (item.childMenus && item.childMenus.length > 0 ) {
                                    item.childMenus.map((some)=>{
                                        arr.push(some.id)
                                        if (some.childMenus && some.childMenus.length > 0 ) {
                                            some.childMenus.map((sub)=>{
                                                arr.push(sub.id)
                                            })
                                        }
                                    })
                                }
                            } else if (item.childMenus && item.childMenus.length > 0 ) { //从数组的子集中寻找id及其父元素
                                item.childMenus.map((some)=>{
                                    if (some.id === id ) {
                                        arr.push(id) //第二级
                                        arr.push(item.id) //第一级id
                                        arr.push(item.parentId)  //模块id
                                        if (some.childMenus && some.childMenus.length > 0 ) {
                                            some.childMenus.map((sub)=>{
                                                arr.push(sub.id)//第三级id
                                            })
                                        }
                                    } else if ( some.childMenus && some.childMenus.length > 0) {
                                        some.childMenus.map((every)=>{
                                            if (every.id === id ) {
                                                arr.push(id)
                                                arr.push(some.id)
                                                arr.push(item.id)
                                                arr.push(item.parentId)
                                            }
                                        })
                                    }
                                })
                            }
                        })
                    })
                })
                this.allParentId = this.allParentId.concat(arr)
                this.allParentId = arrayUnique(this.allParentId) //所有id父子级
            },
        },
        components: {
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .full-width{
        width:100%;
    }
    .authTitle{
        width: 88px;
        /*font-family: "MicrosoftYaHei";*/
        font-size: 15px;
        line-height: 48px;
        text-align: left;
        color: #313131;
    }
    .gray{
        background: #fafafa;
    }
    //模块的选中样式
    .blue {
        background-color: rgba(64,158,255,.1);
        border: 1px solid rgba(64,158,255,.2);
        color: #409EFF;
    }

    .red {
        background-color: rgba(245,108,108,.1);
        border-color: rgba(245,108,108,.2);
        color: #f56c6c;
    }

//tag的样式
.tagStyle{
    margin-left: 120px;
    line-height: 45px;
    .tagStyle-tag{
        margin-left:5px;
        cursor: pointer;
    }
}
//分界线
.ca-client-topic{
    .topic-font{
        /*font-family: 'NSimSun';*/
        font-size: 12px;
        color: #bfbfbf;
        text-align: center;
    }
    .el-col-11{
        text-align: center;
        span{
            display: inline-block;
            width:100%;
            height:1px;
            background: #e5e5e5;
            /*border: solid 1px #e5e5e5;*/
        }
    }
}
.bigTitle{
    font-size: 20px;
}
.smallTitle{
    font-size: 18px;
}
.buttonStyle{
    padding: 50px 0 20px 0;
    text-align: center;
}
</style>
